package com.ddwl.wallet.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.order.QueryUserDistOrderBo;
import com.ddwl.schema.bo.order.SubAgentDistOrderBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.dist.DistVo;
import com.ddwl.schema.vo.wallet.AgentDistStatisticsDto;
import com.ddwl.schema.vo.wallet.DistOrderVo;
import com.ddwl.wallet.service.DistOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 类DistOrderController.java的实现描述：用户分销订单接口
 *
 * @author zach
 * @Date :2020-07-22 17:41.
 */
@Slf4j
@Api(tags = "分销订单接口")
@RequestMapping("dist/order")
@RestController
public class DistOrderController extends BaseController {

    @Resource
    private DistOrderService distOrderService;


    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.MALL})
    @ApiOperation("查询我用户的分销订单")
    public RestVo<PageVo<DistOrderVo>> page(@Valid @RequestBody PageBo<QueryUserDistOrderBo> pageBo) {
        pageBo.getParam().setUserId(getUserId());
        return RestVo.ok(distOrderService.getDistPageNew(pageBo));
    }

    @PostMapping("/wbm/page")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("查询wbm用户的分销订单")
    public RestVo<PageVo<DistOrderVo>> getWbmPage(@Valid @RequestBody PageBo<QueryUserDistOrderBo> pageBo) {
        pageBo.getParam().setUserId(getUserId());
        pageBo.getParam().setType(7);
        return RestVo.ok(distOrderService.getDistPageNew(pageBo));
    }

    @PostMapping("/distPage")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台查询分销订单")
    public RestVo<PageVo<DistOrderVo>> distPage(@Valid @RequestBody PageBo<QueryUserDistOrderBo> pageBo) {
        return RestVo.ok(distOrderService.getDistPageForConsole(pageBo));
    }

    @GetMapping("/recordViews/{source}")
    @ApiOperation("记录点击数")
    public RestVo recordViews(@PathVariable String source) {
        distOrderService.recordViews(source);
        return RestVo.ok();
    }

    @GetMapping("/getDist/{orderId}")
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation("查询订单分销信息")
    public RestVo<List<DistVo>> getDistOrder(@PathVariable String orderId) {
        return RestVo.ok(distOrderService.getDistOrder(orderId));
    }

    @PostMapping("/updateDistOrderUser")
    @ApiOperation("订正分销单分销员电话姓名信息")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    public RestVo updateDistOrderUser() {
        distOrderService.updateDistOrderUser();
        return RestVo.ok();
    }

    @PostMapping("/updateDistRecordUser")
    @ApiOperation("订正浏览记录上级,间接上级信息")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    public RestVo updateDistRecordUser() {
        distOrderService.updateDistRecordUser();
        return RestVo.ok();
    }

    @PostMapping("/subAgentPage")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("查询用户的下级产生的分润")
    public RestVo<PageVo<DistOrderVo>> subAgentPage(@Valid @RequestBody PageBo<SubAgentDistOrderBo> pageBo) {
        SubAgentDistOrderBo param = pageBo.getParam();
        if (null == param) {
            param = new SubAgentDistOrderBo();
        }
        param.setUserId(getUserId());
        return RestVo.ok(distOrderService.subAgentPage(pageBo));
    }

    @GetMapping("/agentDistStatistics")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("查询代理分润统计信息")
    public RestVo<List<AgentDistStatisticsDto>> getAgentDistStatistics(@RequestParam String distUserId, @RequestParam List<String> sources){
        return RestVo.ok(distOrderService.getAgentDistStatistics(distUserId,sources));
    }

}
